package com.redwine.app;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.redwine.app.adapter.BannerViewPager;
import com.redwine.app.adapter.ProcurementAdapter;
import com.redwine.app.chat.ChatActivity;
import com.redwine.app.chat.ChatConstant;
import com.redwine.app.net.GsonRequest;
import com.redwine.app.net.NetworkConstants;
import com.redwine.app.net.responses.BaseResponse;
import com.redwine.app.net.responses.CommonListDataResponse;
import com.redwine.app.net.responses.RedwineDetailResponse;
import com.redwine.app.net.responses.SendMsgEvent;
import com.redwine.app.utils.BitmapUtils;
import com.redwine.app.utils.DimenUtils;
import com.redwine.app.utils.Global;
import com.redwine.app.utils.NetUtil;
import com.redwine.app.utils.Settings;
import com.redwine.app.utils.Utils;
import com.redwine.app.view.AlertDialog;
import com.redwine.app.view.EmptyView;
import com.redwine.app.view.MeasureListView;
import com.redwine.app.view.shareDialog.BottomDialog;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import de.greenrobot.event.EventBus;

import static com.redwine.app.utils.Utils.showToast;

/**
 * 采购详情
 * 作者：gassion on 17/8/23 23:02
 * 最可怕的敌人，就是没有坚强的信念。
 */
public class ProcurementDetailActivity extends BaseActivity {

    @ViewInject(R.id.main_banner_Layout)
    private BannerViewPager goodsBannerLayout;
    @ViewInject(R.id.goods_banner_linear_layout)
    private LinearLayout goodsBannerLinearLayout;
    @ViewInject(R.id.goods_banner_relayout_layout)
    private RelativeLayout goodsBannerRelayoutLayout;
    @ViewInject(R.id.view_feed_banner_inner)
    private RelativeLayout viewFeedBannerInner;
    @ViewInject(R.id.goods_banner_tv_status)
    private TextView bannerTvStatus;
    @ViewInject(R.id.header_title)
    private TextView headerTitle;
    @ViewInject(R.id.layout_back)
    private LinearLayout layoutBack;
    @ViewInject(R.id.layout_right_share)
    private LinearLayout mRightShare;
    @ViewInject(R.id.goods_detail_layout_collect)
    private LinearLayout goodsDetailLayoutCollect;
    @ViewInject(R.id.goods_detail_ll_offer_comments)
    private LinearLayout goodsDetailLayoutComments;
    @ViewInject(R.id.goods_detail_tv_shop_name)
    private TextView goodsDetailTvShopName;
    @ViewInject(R.id.goods_detail_tv_shop_origin)
    private TextView goodsDetailTvShopOrigin;
    @ViewInject(R.id.goods_detail_tv_bill)
    private TextView goodsDetailTvBill;
    @ViewInject(R.id.goods_detail_tv_shop_how_many)
    private TextView goodsDetailTvShopHowMany;
    @ViewInject(R.id.goods_detail_tv_shop_price)
    private TextView goodsDetailTvShopPrice;
    @ViewInject(R.id.goods_detail_tv_shop_end_time)
    private TextView goodsDetailTvShopEndTime;
    @ViewInject(R.id.goods_detail_tv_shop_send_time)
    private TextView goodsDetailTvShopSendTime;
    @ViewInject(R.id.goods_detail_iv_merchant_icon)
    private ImageView goodsDetailIvMerchantIcon;
    @ViewInject(R.id.goods_detail_tv_user_name)
    private TextView goodsDetailTvUserName;
    @ViewInject(R.id.goods_detail_tv_user_address)
    private TextView goodsDetailTvUserAddress;
    @ViewInject(R.id.goods_detail_tv_buy_count)
    private TextView goodsDetailTvBuyCount;
    @ViewInject(R.id.goods_detail_tv_vol_count)
    private TextView goodsDetailTvVolCount;
    @ViewInject(R.id.goods_detail_tv_provider_auth)
    private TextView goodsDetailTvProviderAuth;
    @ViewInject(R.id.goods_measure_list_view)
    private MeasureListView goodsMeasureListView;
    @ViewInject(R.id.goods_detail_tv_my_price)
    private TextView goodsDetailTvMyPrice;
    @ViewInject(R.id.goods_detail_tv_qiu_gou)
    private TextView goodsDetailTvQiuGou;
    @ViewInject(R.id.goods_detail_tv_send_msg)
    private TextView goodsDetailTvSendMsg;
    @ViewInject(R.id.goods_detail_ll_price)
    private LinearLayout goodsDetailLlPrice;
    @ViewInject(R.id.goods_ll_Offer_hint)
    private LinearLayout goodsDetailLlOfferHint;
    @ViewInject(R.id.goods_detail_ll_supplier)
    private LinearLayout goodsDetailLlSupplier;
    @ViewInject(R.id.goods_detail_ll_provider_auth)
    private LinearLayout goodsDetailLlProviderAuth;
    @ViewInject(R.id.goods_detail_tv_comments)
    private TextView goodsDetailTvComments;
    @ViewInject(R.id.goods_detail_tv_collect)
    private TextView goodsDetailTvCollect;
    @ViewInject(R.id.goods_detail_all_layout)
    private LinearLayout goodsDetailAllLayout;
    @ViewInject(R.id.empty_view)
    private EmptyView emptyView;
    private ProcurementAdapter goodsDetailEvaluationAdapter;
    private RedwineDetailResponse.DataEntity.PublishEntity mPublishEntity;
    private RedwineDetailResponse.DataEntity.UserInfoEntity userInfoEntity;
    private RedwineDetailResponse.DataEntity mResponseData;
    private boolean isAccept = false;//是否采纳
    private boolean isQuoted = false;//是否报价
    public static final String SHOP_NAME = "SHOP_NAME";
    public static final String SHOP_UID = "SHOP_UID";
    public static final String SHOP_ID = "SHOP_ID";
    private String mName;
    private String mUid;
    private String mId;
    private Intent intent;
    private View view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        view = LayoutInflater.from(this).inflate(R.layout.activity_procurement_detail, null);
        setContentView(view);
        EventBus.getDefault().register(this);
        ViewUtils.inject(this, view);
        initView();
        requestData();
    }

    private void initView() {
        Intent intent = getIntent();
        if (null != intent) {
            mName = getIntent().getStringExtra(SHOP_NAME);
            mUid = getIntent().getStringExtra(SHOP_UID);
            mId = getIntent().getStringExtra(SHOP_ID);
        } else {
            finish();
        }
        mRightShare.setVisibility(View.VISIBLE);
        headerTitle.setText(mName);
        layoutBack.setVisibility(View.VISIBLE);
        goodsDetailEvaluationAdapter = new ProcurementAdapter(this);
        goodsMeasureListView.setAdapter(goodsDetailEvaluationAdapter);
        goodsMeasureListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //GASSION 评价管理的item点击
            }
        });
    }

    public void requestData() {
        if (!NetUtil.checkNet(this)) {
            showToast(R.string.generic_check);
            setErrorView(emptyView, null);
            return;
        }

        showWaiting();
        isAccept = false;
        isQuoted = false;
        String url = NetworkConstants.REDWINE_DETAIL_URL;
        Map<String, String> params = new LinkedHashMap<>();
        params.put("uid", mUid);
        params.put("publish_id", mId);
        GsonRequest<RedwineDetailResponse> request = new GsonRequest<>(url, Request.Method.POST,
                RedwineDetailResponse.class, false, params, new Response.Listener<RedwineDetailResponse>() {
            @Override
            public void onResponse(RedwineDetailResponse response) {
                dismissWaiting();
                if (response.isSuccess()) {
                    mResponseData = response.getData();
                    updateView(mResponseData);
                } else {
                    setEmptyView(emptyView, null);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                dismissWaiting();
                setEmptyView(emptyView, null);
                showToast(R.string.generic_check);
            }
        });
        APP.getInstance().getRequestQueue().add(request);
    }

    /**
     * 更新view
     *
     * @param responseData
     */
    private void updateView(RedwineDetailResponse.DataEntity responseData) {
        if (null == responseData) {
            setEmptyView(emptyView, null);
            return;
        }

        try {
            mPublishEntity = responseData.getPublish();
            goodsDetailAllLayout.setVisibility(View.VISIBLE);
            if (responseData.getPublish().getUid().equals(Global.user.getUid())) {
                goodsDetailLlOfferHint.setVisibility(View.GONE);//温馨提示你的报价只有自己和采购商可见
                goodsDetailLlProviderAuth.setVisibility(View.GONE);
                goodsDetailLlPrice.setVisibility(View.GONE);
                switch (Integer.valueOf(mPublishEntity.getStatusX())) {

                    case 2:
                        bannerTvStatus.setVisibility(View.VISIBLE);
                        bannerTvStatus.setText("截止报价");
                        goodsDetailTvQiuGou.setVisibility(View.VISIBLE);
                        break;

                    case 7:
                        bannerTvStatus.setVisibility(View.GONE);
                        goodsDetailTvQiuGou.setVisibility(View.VISIBLE);
                        break;

                    case 5:
                        bannerTvStatus.setVisibility(View.VISIBLE);
                        bannerTvStatus.setText("交易成功");
                        goodsDetailTvQiuGou.setVisibility(View.GONE);
                        goodsDetailLlSupplier.setVisibility(View.GONE);
                        break;

                    default:
                        bannerTvStatus.setVisibility(View.GONE);
                        goodsDetailTvQiuGou.setVisibility(View.GONE);
                        goodsDetailLlSupplier.setVisibility(View.VISIBLE);
                        break;

                }
            } else {
                goodsDetailLlOfferHint.setVisibility(View.VISIBLE);
                goodsDetailLlProviderAuth.setVisibility(View.VISIBLE);
                goodsDetailLlSupplier.setVisibility(View.GONE);
                goodsDetailLlPrice.setVisibility(View.VISIBLE);
                switch (Integer.valueOf(mPublishEntity.getStatusX())) {

                    case 2:
                        bannerTvStatus.setVisibility(View.VISIBLE);
                        bannerTvStatus.setText("截止报价 !");
                        goodsDetailTvMyPrice.setVisibility(View.GONE);
                        break;

                    case 7:
                        bannerTvStatus.setVisibility(View.GONE);
                        goodsDetailTvMyPrice.setVisibility(View.GONE);
                        break;

                    case 5:
                        bannerTvStatus.setVisibility(View.VISIBLE);
                        bannerTvStatus.setText("交易成功 !");
                        goodsDetailTvMyPrice.setVisibility(View.GONE);
                        break;

                    default:
                        bannerTvStatus.setVisibility(View.GONE);
                        goodsDetailTvMyPrice.setVisibility(View.VISIBLE);
                        break;

                }
            }
            updateCollectUI(responseData);
            List<String> stringList = super.strConvertList(mPublishEntity.getPic());
            if (!stringList.isEmpty()) {
                updateBannerView(stringList);
            }
            if ("1".equals(mPublishEntity.getInvoice())) {
                goodsDetailTvBill.setText("需要发票");
            } else {
                goodsDetailTvBill.setText("不需要发票");
            }
            headerTitle.setText(mPublishEntity.getTitle());
            goodsDetailTvShopName.setText(mPublishEntity.getTitle());
            goodsDetailTvShopOrigin.setText(mPublishEntity.getCity());
            goodsDetailTvShopHowMany.setText(mPublishEntity.getNum());
            goodsDetailTvShopPrice.setText(mPublishEntity.getPrice());
            Utils.setShowTime(goodsDetailTvShopEndTime, mPublishEntity.getRemain());
            Utils.setShowTime(goodsDetailTvShopSendTime, mPublishEntity.getRemain_before());
            userInfoEntity = responseData.getUser_info();
            BitmapUtils.loadImage(goodsDetailIvMerchantIcon, userInfoEntity.getAvatar(), BitmapUtils.THE_ARTICLE);
            goodsDetailTvUserName.setText(userInfoEntity.getNickname());
            goodsDetailTvUserAddress.setText(userInfoEntity.getCompany());
            RedwineDetailResponse.DataEntity.DealEntity dealEntity = responseData.getDeal();
            goodsDetailTvBuyCount.setText(dealEntity.getPurchase_cout());
            goodsDetailTvVolCount.setText(dealEntity.getPublish_count());
            List<RedwineDetailResponse.DataEntity.QuoteEntity> quoteEntityList = responseData.getQuote();

            goodsDetailLayoutComments.setVisibility(View.VISIBLE);
            if (null != quoteEntityList && !quoteEntityList.isEmpty()) {
                for (int i = 0; i < quoteEntityList.size(); i++) {
                    RedwineDetailResponse.DataEntity.QuoteEntity quoteEntity = quoteEntityList.get(i);
                    if ("2".equals(quoteEntity.getStatusX()))
                        isAccept = true;
                    if (Global.user.getUid().equals(quoteEntity.getUid()))
                        isQuoted = true;
                    break;
                }
                goodsDetailEvaluationAdapter.setData(quoteEntityList, mPublishEntity.getStatusX());
            }
            String supplier_status = responseData.getSupplier_status();
            Settings.setSharedPreferences(Settings.SUPPLIER_STATUS, supplier_status);
            String buyer_status = responseData.getBuyer_status();
            Settings.setSharedPreferences(Settings.BUYER_STATUS, buyer_status);
            switch (Integer.valueOf(supplier_status)) {

                case 4:
                    goodsDetailLlProviderAuth.setVisibility(View.GONE);
                    break;

                default:
                    goodsDetailTvProviderAuth.setText("供应商认证");
                    goodsDetailTvProviderAuth.setEnabled(true);
                    break;


            }
            goodsDetailTvComments.setText(responseData.getQuote_count());
        } catch (Exception e) {
            setEmptyView(emptyView, null);
            e.printStackTrace();
        }

    }

    /**
     * 更新ui是否收藏
     *
     * @param responseData
     */
    private void updateCollectUI(RedwineDetailResponse.DataEntity responseData) {
        if (responseData.isCollection()) {
            //已收藏
            goodsDetailTvCollect.setText(R.string.already_collected);
            goodsDetailTvCollect.setCompoundDrawables(getIdDrawable(R.mipmap.icon_collect_select), null, null, null);
        } else {
            //未收藏
            goodsDetailTvCollect.setText(R.string.collection);
            goodsDetailTvCollect.setCompoundDrawables(getIdDrawable(R.mipmap.icon_collect_normal), null, null, null);
        }
    }

    /**
     * 更新banner显示
     * 作者：gassion on 17/8/16 23:31
     * 最可怕的敌人，就是没有坚强的信念。
     */
    private void updateBannerView(final List<String> stringList) {
        int screenWidth = DimenUtils.getWindowsWidth(this) - DimenUtils.dip2px(16);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, screenWidth / 2);
        viewFeedBannerInner.setLayoutParams(params);
        goodsBannerLayout.setRootView(view);
        goodsBannerLayout.setVisibility(View.VISIBLE, DimenUtils.dp2px(20));
        goodsBannerLayout.setPagerAdapter(new BannerViewPager.BannerViewPagerAdapter() {
            @Override
            public int bannerImageCount() {
                return stringList.size();
            }

            @Override
            public String bannerImageUrlAtIndex(int index) {
                return stringList.get(index);
            }

            @Override
            public void bannerDidSelectAtIndex(int index) {
                Intent intent = new Intent(ProcurementDetailActivity.this, ImagePagerActivity.class);
                intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, (ArrayList) stringList);
                intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, index);
                startActivity(intent);
            }
        });
    }

    @OnClick({R.id.goods_detail_tv_qiu_gou, R.id.layout_back, R.id.goods_detail_tv_my_price, R.id.goods_detail_tv_deal_close,
            R.id.goods_detail_tv_deal_success, R.id.goods_detail_tv_provider_auth,
            R.id.goods_detail_tv_send_msg, R.id.goods_detail_layout_collect, R.id.layout_right_share})
    public void mClick(View v) {
        switch (v.getId()) {

            case R.id.layout_back:
                finish();
                break;

            case R.id.goods_detail_tv_qiu_gou:
                AlertDialog.Builder builder = new AlertDialog.Builder(ProcurementDetailActivity.this);
                builder.setTitle(getString(R.string.hint));
                builder.setMessage(getString(R.string.hint_sure_you_want_to_buy_again));
                builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.setPositiveButton(getString(R.string.confirm), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        requestAgainPurchaseData();
                    }
                });
                AlertDialog mDialog = builder.create();
                mDialog.setCancelable(false);
                mDialog.show();
                break;

            case R.id.goods_detail_tv_my_price:
                //我要报价
                if (!isQuoted) {
                    intent = new Intent(ProcurementDetailActivity.this, OfferActivity.class);
                    intent.putExtra(OfferActivity.PUBLISH_ENTITY, mPublishEntity);
                    startActivity(intent);
                } else {
                    Utils.showToast("您已报价，请勿重复报价。");
                }
                break;

            case R.id.goods_detail_tv_send_msg:
                intent = new Intent(ProcurementDetailActivity.this, ChatActivity.class);
                intent.putExtra(ChatConstant.EXTRA_USER_ID, userInfoEntity.getUid());//传递用户的唯一id
                intent.putExtra(ChatConstant.EXTRA_USER_NICK_NAME, userInfoEntity.getNickname());//传递用户的唯一id
                intent.putExtra(ChatConstant.EXTRA_USER_AVATAR, userInfoEntity.getAvatar());
                startActivity(intent);
                break;

            case R.id.goods_detail_tv_deal_close:
                if (!isAccept) {
                    confirmDialog(true);
                }
                break;

            case R.id.goods_detail_tv_deal_success:
                if (!isAccept) {
                    confirmDialog(false);
                }
                break;

            case R.id.goods_detail_tv_provider_auth:
                intent = new Intent(ProcurementDetailActivity.this, ApplyForSupplierActivity.class);
                intent.putExtra(ApplyForSupplierActivity.PUBLISH_ENTITY, mPublishEntity);
                startActivity(intent);
                break;

            case R.id.goods_detail_layout_collect:
                if (mResponseData.isCollection()) {
                    requestCancelCollectionData();
                } else {
                    requestCollectionData();
                }
                break;

            case R.id.layout_right_share:
                List<String> stringList = super.strConvertList(mPublishEntity.getPic());
                new BottomDialog(ProcurementDetailActivity.this)
                        .toShareParams(mPublishEntity.getTitle(), mPublishEntity.getShareUrl(), stringList.get(0),
                                mPublishEntity.getContent()).show();
                break;
        }
    }

    private void confirmDialog(final boolean isClose) {
        AlertDialog.Builder builder = new AlertDialog.Builder(ProcurementDetailActivity.this);
        builder.setTitle(getString(R.string.hint));
        builder.setMessage(getString(R.string.hint_cannot_be_retrieved_after_operation));
        builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.setPositiveButton(getString(R.string.confirm), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                if (isClose) {
                    requestPurchaseCloseData();
                } else {
                    requestPurchaseSuccessData();
                }
            }
        });
        AlertDialog mDialog = builder.create();
        mDialog.setCancelable(false);
        mDialog.show();
    }

    public void onEventMainThread(SendMsgEvent event) {
        if (event.getSendType() == SendMsgEvent.REFURBISH_PROCUREMENT_DETAIL_DATA) {
            requestData();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    /**
     * 取消收藏
     */
    private void requestCancelCollectionData() {
        showWaiting();
        String url = NetworkConstants.CANCLE_COLLECTION_URL;
        Map<String, String> params = new LinkedHashMap<>();
        params.put("uid", Global.user.getUid());
        params.put("collection_id", mResponseData.getIs_collectionis());
        GsonRequest<BaseResponse> request = new GsonRequest<>(url, Request.Method.POST,
                BaseResponse.class, false, params, new Response.Listener<BaseResponse>() {
            @Override
            public void onResponse(BaseResponse response) {
                dismissWaiting();
                if (response.isSuccess()) {
                    EventBus.getDefault().post(new SendMsgEvent(SendMsgEvent.REFURBISH_MY_COLLECTION));
                    mResponseData.setIs_collectionis("0");
                    updateCollectUI(mResponseData);
                } else {
                    showToast(response.getMsg());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                dismissWaiting();
                showToast(error.getMessage());
            }
        });
        APP.getInstance().getRequestQueue().add(request);
    }

    /**
     * 收藏
     */
    private void requestCollectionData() {
        showWaiting();
        String url = NetworkConstants.COLLECTION_URL;
        Map<String, String> params = new LinkedHashMap<>();
        params.put("uid", Global.user.getUid());
        params.put("type", "2");
        params.put("product_id", mPublishEntity.getId());
        GsonRequest<CommonListDataResponse> request = new GsonRequest<>(url, Request.Method.POST,
                CommonListDataResponse.class, false, params, new Response.Listener<CommonListDataResponse>() {
            @Override
            public void onResponse(CommonListDataResponse response) {
                dismissWaiting();
                if (response.isSuccess()) {
                    List<String> responseData = response.getData();
                    for (int i = 0; i < responseData.size(); i++) {
                        mResponseData.setIs_collectionis(responseData.get(i));
                    }
                    EventBus.getDefault().post(new SendMsgEvent(SendMsgEvent.REFURBISH_MY_COLLECTION));
                    updateCollectUI(mResponseData);
                } else {
                    showToast(response.getMsg());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                dismissWaiting();
                showToast(error.getMessage());
            }
        });
        APP.getInstance().getRequestQueue().add(request);
    }

    /**
     * 交易成功
     */
    private void requestPurchaseSuccessData() {
        showWaiting();
        String url = NetworkConstants.PURCHASE_SUCCESS_URL;
        Map<String, String> params = new LinkedHashMap<>();
        params.put("purchase_id", mPublishEntity.getId());
        GsonRequest<BaseResponse> request = new GsonRequest<>(url, Request.Method.POST,
                BaseResponse.class, false, params, new Response.Listener<BaseResponse>() {
            @Override
            public void onResponse(BaseResponse response) {
                dismissWaiting();
                if (response.isSuccess()) {
                    EventBus.getDefault().post(new SendMsgEvent(SendMsgEvent.REFURBISH_MAIN_DATA));
                    finish();
                } else {
                    showToast(response.getMsg());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                dismissWaiting();
                showToast(error.getMessage());
            }
        });
        APP.getInstance().getRequestQueue().add(request);
    }


    /**
     * 交易关闭
     */
    private void requestPurchaseCloseData() {
        showWaiting();
        String url = NetworkConstants.PURCHASE_CLOSE_URL;
        Map<String, String> params = new LinkedHashMap<>();
        params.put("purchase_id", mPublishEntity.getId());
        GsonRequest<BaseResponse> request = new GsonRequest<>(url, Request.Method.POST,
                BaseResponse.class, false, params, new Response.Listener<BaseResponse>() {
            @Override
            public void onResponse(BaseResponse response) {
                dismissWaiting();
                if (response.isSuccess()) {
                    EventBus.getDefault().post(new SendMsgEvent(SendMsgEvent.REFURBISH_MAIN_DATA));
                    finish();
                } else {
                    showToast(response.getMsg());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                dismissWaiting();
                showToast(error.getMessage());
            }
        });
        APP.getInstance().getRequestQueue().add(request);
    }

    /**
     * 再次发布
     */
    private void requestAgainPurchaseData() {
        showWaiting();
        String url = NetworkConstants.AGAIN_PURCHASE_URL;
        Map<String, String> params = new LinkedHashMap<>();
        params.put("purchase_id", mPublishEntity.getId());
        GsonRequest<BaseResponse> request = new GsonRequest<>(url, Request.Method.POST,
                BaseResponse.class, false, params, new Response.Listener<BaseResponse>() {
            @Override
            public void onResponse(BaseResponse response) {
                dismissWaiting();
                if (response.isSuccess()) {
                    requestData();
                    EventBus.getDefault().post(new SendMsgEvent(SendMsgEvent.REFURBISH_MAIN_DATA));
                } else {
                    showToast(response.getMsg());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                dismissWaiting();
                showToast(error.getMessage());
            }
        });
        APP.getInstance().getRequestQueue().add(request);
    }


    @Override
    protected void emptyOnclick() {
        emptyView.bind();
        requestData();
    }

    @Override
    public void onResume() {
        super.onResume();
        dismissWaiting();
    }
}
